<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="所属分局" prop="whichBelongs">
              <el-select v-model="queryParams.whichBelongs" placeholder="请选择所属分局">
                <el-option
                  v-for="dict in dict.type.which_belongs"
                  :key="dict.label"
                  :label="dict.label"
                  :value="dict.label"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="辖区单位" prop="jurisdictionalUnits">
              <el-select v-model="queryParams.jurisdictionalUnits" placeholder="请选择所属分局">
                <el-option
                  v-for="dict in dict.type.jurisdictional_units"
                  :key="dict.label"
                  :label="dict.label"
                  :value="dict.label"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="处理结果" prop="processingResults">
              <el-select v-model="queryParams.processingResults" placeholder="请选择所属分局">
                <el-option
                  v-for="dict in dict.type.processing_results"
                  :key="dict.label"
                  :label="dict.label"
                  :value="dict.label"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="举报时间">
                <el-date-picker v-model="daterangeReportTime" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
                    range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
            </el-form-item>
            <el-form-item label="反馈内容" prop="feedbackContent">
                <el-input v-model="queryParams.feedbackContent" placeholder="请输入反馈内容" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <!-- 
            <el-form-item label="处理结果" prop="processingResults">
                <el-input v-model="queryParams.processingResults" placeholder="请输入处理结果" clearable size="small" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="警情标签" prop="policeLabel">
                <el-input v-model="queryParams.policeLabel" placeholder="请输入警情标签" clearable size="small" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="一级归口" prop="firstLevelCentralizedManagement">
                <el-input v-model="queryParams.firstLevelCentralizedManagement" placeholder="请输入一级归口" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="二级归口" prop="secondaryCentralizedManagement">
                <el-input v-model="queryParams.secondaryCentralizedManagement" placeholder="请输入二级归口" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="三级归口" prop="thirdLevelCentralizedManagement">
                <el-input v-model="queryParams.thirdLevelCentralizedManagement" placeholder="请输入三级归口" clearable size="small"
                    @keyup.enter.native="handleQuery" />
            </el-form-item> -->
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['bt:alarm:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
                    v-hasPermi="['bt:alarm:edit']">修改</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
                    v-hasPermi="['bt:alarm:remove']">删除</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                    v-hasPermi="['bt:alarm:export']">导出</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport">导入</el-button>
            </el-col>

            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="alarmList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <!-- <el-table-column label="id" align="center" prop="id" /> -->
            <el-table-column label="所属分局" align="center" prop="whichBelongs" />
            <el-table-column label="辖区单位" align="center" prop="jurisdictionalUnits" />
            <el-table-column label="行政区划" align="center" prop="administrativeDivision" />
            <el-table-column label="反馈内容" align="center" prop="feedbackContent" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                    <div v-html="scope.row.feedbackContent"></div>
                </template>
            </el-table-column>
            <el-table-column label="处理结果" align="center" prop="processingResults" />
            <el-table-column label="事件状态" align="center" prop="eventStatus" />
            <el-table-column label="警情标签" align="center" prop="policeLabel" />
            <el-table-column label="一级归口" align="center" prop="firstLevelCentralizedManagement" />
            <el-table-column label="二级归口" align="center" prop="secondaryCentralizedManagement" />
            <el-table-column label="三级归口" align="center" prop="thirdLevelCentralizedManagement" />
            <el-table-column label="举报时间" align="center" prop="reportTime" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.reportTime, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="备注" align="center" prop="remark" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-tickets" v-hasPermi="['bt:alarm:query']"
                        @click="handleDetail(scope.row)">详情
                    </el-button>
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['bt:alarm:edit']">修改</el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                        v-hasPermi="['bt:alarm:remove']">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

        <!-- 添加或修改包头市公安局噪声污染报警信息对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <el-form-item label="所属分局" prop="whichBelongs">
                    <el-input v-model="form.whichBelongs" placeholder="请输入所属分局" />
                </el-form-item>
                <el-form-item label="辖区单位" prop="jurisdictionalUnits">
                    <el-input v-model="form.jurisdictionalUnits" placeholder="请输入辖区单位" />
                </el-form-item>
                <el-form-item label="行政区划" prop="administrativeDivision">
                    <el-input v-model="form.administrativeDivision" placeholder="请输入行政区划" />
                </el-form-item>
                <el-form-item label="反馈内容">
                    <editor v-model="form.feedbackContent" :min-height="192" />
                </el-form-item>
                <el-form-item label="处理结果" prop="processingResults">
                    <el-input v-model="form.processingResults" placeholder="请输入处理结果" />
                </el-form-item>
                <el-form-item label="警情标签" prop="policeLabel">
                    <el-input v-model="form.policeLabel" placeholder="请输入警情标签" />
                </el-form-item>
                <el-form-item label="一级归口" prop="firstLevelCentralizedManagement">
                    <el-input v-model="form.firstLevelCentralizedManagement" placeholder="请输入一级归口" />
                </el-form-item>
                <el-form-item label="二级归口" prop="secondaryCentralizedManagement">
                    <el-input v-model="form.secondaryCentralizedManagement" placeholder="请输入二级归口" />
                </el-form-item>
                <el-form-item label="三级归口" prop="thirdLevelCentralizedManagement">
                    <el-input v-model="form.thirdLevelCentralizedManagement" placeholder="请输入三级归口" />
                </el-form-item>
                <el-form-item label="举报时间" prop="reportTime">
                    <el-date-picker clearable size="small" v-model="form.reportTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择举报时间">
                    </el-date-picker>
                </el-form-item>
                <!-- <el-form-item label="逻辑删除标识(0-正常;非0删除)" prop="delFlag">
                    <el-input v-model="form.delFlag" placeholder="请输入逻辑删除标识(0-正常;非0删除)" />
                </el-form-item> -->
                <el-form-item label="备注" prop="remark">
                    <el-input v-model="form.remark" placeholder="请输入备注" />
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>    
        
        
        <!-- 详情 -->
        <el-dialog class="fromDetail" title="详情" :visible.sync="openDetail" width="1000px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="130px">

                <!-- <div class="fromtitle"  v-if="form.finalExecuteCase">
                    <div>终结本次执行案件详情</div>
                </div> -->
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="所属分局" prop="term">
                            <div>{{form.whichBelongs}}</div>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="辖区单位" prop="term">
                            <div>{{form.jurisdictionalUnits}}</div>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="行政区划" prop="term">
                            <div>{{form.administrativeDivision}}</div>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="反馈内容" prop="term">
                            <div>{{form.feedbackContent}}</div>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="处理结果" prop="term">
                            <div>{{form.processingResults}}</div>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="警情标签" prop="term">
                            <div>{{form.policeLabel}}</div>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="一级归口" prop="term">
                            <div>{{form.firstLevelCentralizedManagement}}</div>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="二级归口" prop="term">
                            <div>{{form.secondaryCentralizedManagement}}</div>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="三级归口" prop="term">
                            <div>{{form.thirdLevelCentralizedManagement}}</div>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="举报时间" prop="term">
                            <div>{{form.reportTime}}</div>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="备注" prop="term">
                            <div>{{form.remark}}</div>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </el-dialog>
        
        <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <!-- <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
          </div> -->
          <span>仅允许导入xls、xlsx格式文件。</span>
          <!-- <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link> -->
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    </div>
</template>

<script>
import { listAlarm, getAlarm, delAlarm, addAlarm, updateAlarm } from "@/api/callThePolice";
import { getToken } from "@/utils/auth";

export default {
    name: "Alarm",
    
dicts: ['which_belongs','jurisdictional_units','processing_results'],
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 包头市公安局噪声污染报警信息表格数据
            alarmList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 是否显示详情弹出层
            openDetail: false,
            // 备注时间范围
            daterangeReportTime: [],
            // 备注时间范围
            daterangeCreateTime: [],
            // 备注时间范围
            daterangeUpdateTime: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                whichBelongs: null,
                jurisdictionalUnits: null,
                administrativeDivision: null,
                feedbackContent: null,
                processingResults: null,
                eventStatus: null,
                policeLabel: null,
                firstLevelCentralizedManagement: null,
                secondaryCentralizedManagement: null,
                thirdLevelCentralizedManagement: null,
                reportTime: null,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
            },
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/bt/alarm/import/data"
      },
        };
    },
    created() {
        this.getList();
    },
    methods: {
        /** 查询包头市公安局噪声污染报警信息列表 */
        getList() {
            this.loading = true;
            this.queryParams.params = {};
            if (null != this.daterangeReportTime && '' != this.daterangeReportTime) {
                this.queryParams.params["beginReportTime"] = this.daterangeReportTime[0];
                this.queryParams.params["endReportTime"] = this.daterangeReportTime[1];
            }
            if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
                this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
                this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
            }
            if (null != this.daterangeUpdateTime && '' != this.daterangeUpdateTime) {
                this.queryParams.params["beginUpdateTime"] = this.daterangeUpdateTime[0];
                this.queryParams.params["endUpdateTime"] = this.daterangeUpdateTime[1];
            }
            listAlarm(this.queryParams).then(response => {
                this.alarmList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                whichBelongs: null,
                jurisdictionalUnits: null,
                administrativeDivision: null,
                feedbackContent: null,
                processingResults: null,
                eventStatus: "0",
                policeLabel: null,
                firstLevelCentralizedManagement: null,
                secondaryCentralizedManagement: null,
                thirdLevelCentralizedManagement: null,
                reportTime: null,
                delFlag: null,
                createBy: null,
                createTime: null,
                updateBy: null,
                updateTime: null,
                remark: null
            };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.daterangeReportTime = [];
            this.daterangeCreateTime = [];
            this.daterangeUpdateTime = [];
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = "添加包头市公安局噪声污染报警信息";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            const id = row.id || this.ids
            getAlarm(id).then(response => {
                this.form = response.data;
                this.open = true;
                this.title = "修改包头市公安局噪声污染报警信息";
            });
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.form.id != null) {
                        updateAlarm(this.form).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.getList();
                        });
                    } else {
                        addAlarm(this.form).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.open = false;
                            this.getList();
                        });
                    }
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const ids = row.id || this.ids;
            this.$modal.confirm('是否确认删除包头市公安局噪声污染报警信息编号为"' + ids + '"的数据项？').then(function () {
                return delAlarm(ids);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download('bt/alarm/export', {
                ...this.queryParams
            }, `alarm_${new Date().getTime()}.xlsx`)
        },
        // 查看详情
        handleDetail(row) {
            // this.reset();
            const id = row.id || this.ids
            getAlarm(id).then(response => {
                this.form = response.data;
                this.openDetail = true;
            });
        },
        
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('system/user/importTemplate', {
      }, `user_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
    }
};
</script>
